// pages/index/HomeNav/psy/psy.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    downurl: 'http://localhost:8080/file/downLoad?fileName=',
    url: '',
    heartmark: '',
    pageNum: 1,
    totalPageCount: 0,
  },
  getHearkmark() {
   
    // 显示加载中
    wx.showLoading({
      title: '数据加载中...',
      mask: true
    })
    let that = this
    wx.request({
      method: "GET",
      url: that.data.url + '/hearmark/getall',
      data: {
        pageNum: that.data.pageNum,
        pageSize: 10
      },
      success(resp) {
        that.setData({
          heartmark: [...that.data.heartmark, ...resp.data.data.list],
          totalPageCount: resp.data.data.pages,
        })
      },
      
     
    })
    wx.hideLoading()
  },
  onLoad() {
    this.setData({
      url: app.globalData.URL
    })
    this.getHearkmark()
  },
  tosentiment() {
    wx.navigateTo({
      url: './sentiment/sentiment',
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    // 加载第一页数据，数据重置
    this.setData({
      heartmark: [],
      pageNum: 1,
      totalPageCount: 0,
    })
    this.getHearkmark();
    // 关闭加载提示框
    wx.hideLoading()
    // 手动关闭下拉刷新
    wx.stopPullDownRefresh()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoading) return;
    if (this.data.pageNum >= this.data.totalPageCount) {
      wx.showToast({
        title: '没有更多数据!',
        icon: 'none'
      })
      return;
    }
    this.setData({
      pageNum: this.data.pageNum + 1
    })
    this.getHearkmark();
  },
})